///////////////////////////////////////////////////////////////////////////////
// Name:        dump.cpp
// Purpose:     Dump functions
// Copyright:   (c) 2006, Ivan Laptev, TT Solutions
// License:     GPL, Please contact us for commercial license.
//              http://www.tt-solutions.com/
///////////////////////////////////////////////////////////////////////////////
#include "objectdet/dump.h"

#define IGNORE_DUMPS

void DumpMatrix( std::string const & filename, pMat const & mat)
{
#ifndef IGNORE_DUMPS
    pFileStorage fs = OpenFileStorage(filename, RWM_Write);
    WriteMatrixToFile(fs, "matrix", mat);
#endif
}

void DumpResultingWindows(std::string const& filename, SubWindows const& wins)
{
    (void)filename;
    (void)wins;
#ifndef IGNORE_DUMPS
    if (wins.empty())
    {
        std::cout << "No matching sub_windows...\n" << std::flush;
        return;
    }
    // 6:
    //  4 window coordinates
    //  1 dfce
    //  1 cluster_size
    pMat results = CreateMat( wins.size(), 6, CV_32F );

    unsigned int count = 0;
    for (SubWindows::const_iterator cit = wins.begin(); cit != wins.end(); ++cit)
    {
        if (++count < 10)
        {
            std::cout << ">> matching window (" << cit->stage << ") [" << count << "/" << wins.size() << "]("
                                                   << cit->x << ","
                                                   << cit->y << ","
                                                   << (cit->x + cit->w) << ","
                                                   << (cit->y + cit->h) << ";" << cit->cluster_size << ")\n" << std::flush;
        }
        float * f = &CV_MAT_ELEM( *results, float, cit - wins.begin(), 0 );
        *f = cit->x;
        *++f = cit->y;
        *++f = cit->w;
        *++f = cit->h;

        *++f = cit->dfce;
        *++f = cit->cluster_size;
    }

    DumpMatrix( filename, results );
#endif
}

